package com.settlement.system.service.impl;

import com.settlement.system.mapper.TblWpAccountConfigMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblWpAccountConfig;
import com.settlement.system.service.ITblWpAccountConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.settlement.system.mapper.BaseMapper;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.Map;

/**
 * WP-账号配置 服务实现类
 * @author Ximi
 * @since 2020-10-28
 */
@Slf4j
@Service
public class TblWpAccountConfigServiceImpl extends BaseServiceImpl implements ITblWpAccountConfigService {

    @Resource
    private TblWpAccountConfigMapper tblWpAccountConfigMapper;

    @Override
    public BaseMapper init() {
        return tblWpAccountConfigMapper;
    }

    @Override
    public TblWpAccountConfig getFoot(Map<String, Object> params) throws ServiceException {
        try {
            return tblWpAccountConfigMapper.getFoot(params);
        } catch (Exception ex) {
            log.error("获取合计异常", ex);
            throw new ServiceException("获取合计异常", ex);
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void save(TblWpAccountConfig originData,TblWpAccountConfig newData) throws ServiceException {
        if(originData!=null){
            newData.setCreateTime(originData.getCreateTime());
            newData.setCreateUser(originData.getCreateUser());
            newData.setId(originData.getId());
            deleteById(originData.getId());
        }
        insert(newData);
    }
}

